import java.util.Arrays;
import java.util.Comparator;

public class Main {
    public static void main(String[] args) {
        Solution s = new Solution();
//        System.out.println(s.reconstructQueue(new int[][]{{7,0}}));
    }
}


class Solution {
    public int[][] reconstructQueue(int[][] people) {
        int[][] queue = new int[people.length][];
        Arrays.sort(people, Comparator.comparingInt(p -> p[0]));
//        System.out.println(Arrays.deepToString(people));
        for (int[] each : people) {
            int greater = each[1];
            int space = 0;
            int i;
            for (i = 0; i < queue.length; i++) {
                if (queue[i] == null || queue[i][0] == each[0]) {
                    space++;
                    if (space > greater) {
                        break;
                    }
                }
            }
            queue[i] = each;
        }
        return queue;
    }
}